package synchronize.synchronize003;

public class myObjectTest {

    public synchronized void method1() {
        try {
            System.out.println(Thread.currentThread().getName());
            Thread.sleep(4000);
        } catch (Exception exp) {
            exp.printStackTrace();
        }

    }

    public synchronized void method2() {
        try {
            System.out.println(Thread.currentThread().getName());
        } catch (Exception exp) {
            exp.printStackTrace();
        }
    }

    public static void main(String[] args) {
        myObjectTest obj = new myObjectTest();
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                obj.method1();
            }
        },"t1");

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                obj.method2();
            }
        },"t2");

        t1.start();
        t2.start();
    }

}
